<?php /* Smarty version Smarty-3.1.14, created on 2014-03-27 15:01:21
         compiled from "F:\PDC\ProjectEnv\wauf2014\20140117v4\Sites\Admincp\Tpl\EasyUI\article_list.html" */ ?>
<?php /*%%SmartyHeaderCode:3028152f8ca219be855-90991483%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_valid = $_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    'abb7885a23eb0211f8863ccca7d4fe11133780f8' => 
    array (
      0 => 'F:\\PDC\\ProjectEnv\\wauf2014\\20140117v4\\Sites\\Admincp\\Tpl\\EasyUI\\article_list.html',
      1 => 1395736706,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '3028152f8ca219be855-90991483',
  'function' => 
  array (
  ),
  'version' => 'Smarty-3.1.14',
  'unifunc' => 'content_52f8ca21a473f5_33678626',
  'has_nocache_code' => false,
),false); /*/%%SmartyHeaderCode%%*/?>
<?php if ($_valid && !is_callable('content_52f8ca21a473f5_33678626')) {function content_52f8ca21a473f5_33678626($_smarty_tpl) {?><div id="p" class="easyui-panel" title="摘要" style="width:700px;padding:10px;">
    <table><tr><td>在这里管理文章...</td></tr></table>
</div>
<table id="dg" title="文章管理" class="easyui-datagrid" style="width:700px;height:250px" url="?m=Api/Article"  toolbar="#toolbar" pagination="true"  rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
        <tr>
            <th field="ID" width="50">编号</th>
            <th field="Title" width="50">标题</th>
            <th field="VisitCount" width="50">浏览量</th>
            <th field="CreatedTime" width="50">发布时间</th>
            <th field="State" width="50" data-options="formatter:function(v,r,i){return getStateStr(r.ID,v);}">状态</th>
        </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">新增</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editItem()">编辑</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyItem()">删除</a>
</div>
    
<div id="dlg" class="easyui-dialog" style="width:640px;height:500px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
    <div class="ftitle">编辑文章</div>
    <form id="fm" method="post">
        <div class="fitem">
            <label>标题：</label>
            <input name="title" class="easyui-validatebox" size='60' required="true" />
        </div>
        <div class="fitem">
            <label>分类：</label>
            <input class="easyui-combobox" name="catalog"  data-options="url:'?m=Api/Catalog&tag=ARTICLE'">
        </div>
        <div class="fitem">
            <label>内容：</label>
            <textarea name="content" class="editor" rows="6"></textarea>
        </div>
        <input type='hidden' name='id' />
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" id="btnSave" onclick="saveItem()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
    <script type="text/javascript">
        var apiurl='?m=Api/Article';
        function newItem(){
            $('#dlg').dialog('open').dialog('setTitle','新增');
            $('#fm').form('clear');
            setEditor();
        }
        function editItem(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('setTitle','编辑');
                //$('#fm').form('load',row);
                $('#fm').form('load',apiurl+'&action=read_one&id='+row.ID);
                setEditor();
            }
        }
        function saveItem(){
            $('#fm').form('submit',{
                url: apiurl+'&action=save',
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.errorMsg){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }
        function destroyItem(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('操作确认','您确定要删除此记录吗?',function(r){
                    if (r){
                        $.post(apiurl+'&action=remove',{id:row.ID},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
        /**
         * 获取状态的值
         * @param {type} id
         * @param {type} v
         * @returns {String}
         * @since 1.0 2014-3-22 by sutroon
         */
        function getStateStr(id,v){
            return v==1?'<a href="javascript:void(0)" onclick="setItemState('+id+',0);">显示</a>':'<a href="javascript:void(0)" onclick="setItemState('+id+',1);">隐藏<a>'
        }
        /**
         * 更新记录的状态
         * @param {type} id
         * @param {type} v
         * @returns {undefined}
         * @since 1.0 2014-3-22 by sutroon
         */
        function setItemState(id,v){
            alert(id);
            $.post(apiurl+'&action=set_state',{id:id,state:v},function(result){
                            if (result.success){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
        }
        
    </script><?php }} ?>